<?php
require_once ("../src/db/connectdatabase.php");

function getInstallmentRates($bank) {
	$con = new ConnectDB();
	$tbl = "installmentrate";
	$fn = array('rate_id', 'bankname', 'cata', 'catb', 'others', 'prepaymentcharge', 'processfee', 'dateupdate', 'bankid', 'banklogo');
	$condetion = array('isuse' => true);
	$flike = array('bankid' => $bank);
	return $con -> getvalueall($tbl, $fn, $condetion, $flike, 'dateupdate');
}

function int_to_date($int)
{
    $time  = date("d/m/Y", $int);
    return $time;
}

$banksear = "";
if(isset($_GET['selectbank'])) {
	$banksear = $_GET['selectbank'];
}

$arrrate = getInstallmentRates($banksear);
?>
<style>
.listquestionview table {
	width: 900px;
	max-width: 900px;
}

table td {
	margin-top: 2px;
	border: 1px solid;
	border-radius: 2px 2px 2px 2px;
}

table tr:hover td {
	background: #FFC;
}

.title {
	text-align: center;
	background-color: #0088cc;
	min-height: 40px;
	-moz-border-radius: 8px 8px 0px 0px;
	-webkit-border-radius: 8px 8px 0px 0px;
	border-radius: 8px 8px 0px 0px;
	color: #FFF;
}

.stylequestionname {
	width: 150px;
}

.styledatecreatequestion {
	width: 100px;
	max-width: 100px;
	text-align: center;
}

.styleacctionquestion {
	width: 100px;
	text-align: center;
	max-width: 100px;
}

.namequestionline {
	text-align: center;
	padding-left: 5px;
	padding-right: 5px;
	background: url(../images/bg-login.png);
	-moz-border-radius: 2px 2px 2px 2px;
	-webkit-border-radius: 2px 2px 2px 2px;
	border-radius: 2px 2px 2px 2px;
}

table td img {
	cursor: pointer;
}

.linequestiondate {
	text-align: center;
}
.searchforlaisuat select {
	width: 170px;
	height: 30px;
	padding: 5px;
	margin-left: 5px;
	margin-right: 5px;
	margin-bottom: 5px;
}

.stylestt {
	width: 70px;
}
</style>
<h3>Lãi Xuất Vay Trả Góp</h3>
<div class="searchforlaisuat">
<form action="admin.php" method="get">
	<input type="hidden" value="quanlivay" name="content" />
    <input type="hidden" value="vay_tra_gop" name="as" /><input type="hidden" value="installmentrateall" name="adrt" />
	<h4 style="color:#03F; margin-bottom: -10px;">Lọc Theo:</h4><br>
	<label for="selectbank">Ngân Hàng</label>
	<select name="selectbank" class="selectbank">
    	<option value="">----Chọn Ngân Hàng----</option>
    </select>
    <input type="submit" value="Lọc" style="border-radius: 5px; padding:2px; width:50px; background:#03F; color:#FFF; font-weight:bold;" />
</form>
</div><hr /><br />

<div style="color: red;">
<?php
	if(isset($_GET['mess'])) {
		echo($_GET['mess']);
	}
?>
</div>
<form action="../src/control/admininstallmentrate.php" method="post">
<div><a href="admin.php?content=quanlivay&&as=vay_tra_gop&&adrt=addinstallmentrate"><img src="../images/icon-add.jpg" title="Thêm Lãi Suất Trả Góp Ngân Hàng" />Thêm Lãi Suất Trả Góp Ngân Hàng</a> &nbsp;&nbsp;|&nbsp;&nbsp; <input type="hidden" name="acc" value="del" /><input type="submit" value="Xóa Danh Sách Đã Chọn" style="border-radius: 5px; padding:5px; width:200px; background:#03F; color:#FFF; font-weight:bold;" /></div>
<div class="listquestionview">
	<table>
    	<tr>
        	<th class="title"><input type="checkbox" class="checkall" title="Chọn Tất Cả" /></th>
            <th class="stylestt title">STT</th>
        	<th class="stylequestionname title">Ngân Hàng</th>
            <th class="stylequestionname title">CAT A</th>
            <th class="stylequestionname title">CAT B</th>
            <th class="stylequestionname title">Khác</th>
            <th class="styledatecreatequestion title">Phí Trả Trước</th>
            <th class="styledatecreatequestion title">Lệ Phí Xử Lý</th>
            <th class="styledatecreatequestion title">Ngày Cập Nhật</th>
            <th class="styleacctionquestion title">Chức Năng</th>
        </tr>
        <?php
		if(count($arrrate) > 0) {
			$i = 0;
			foreach($arrrate as $entry) {
				$i++;
		?>
        <tr>
        	<td class="namequestionline"><input type="checkbox" value="<?php echo($entry[0]) ?>" title="Chọn để xóa" name="iddels[]" class="linecheckall" /></td>
            <td class="namequestionline"><?php echo($i) ?></td>
        	<td class="namequestionline"><img width="90px" src="../<?php echo($entry[9]) ?>" title="<?php echo($entry[1]) ?> (<?php echo($entry[8]) ?>)" /></td>
            <td class="namequestionline"><?php echo($entry[2]) ?></td>
            <td class="namequestionline"><?php echo($entry[3]) ?></td>
            <td class="namequestionline"><?php echo($entry[4]) ?></td>
            <td class="namequestionline"><?php echo($entry[5]) ?></td>
            <td class="namequestionline"><?php echo($entry[6]) ?></td>
            <td class="namequestionline"><?php echo(int_to_date($entry[7])) ?></td>
            <td class="namequestionline"><img class="class-edit-link" src="../images/icon-edit.gif" title="Chỉnh Sửa Lãi Suất Trả Góp Ngân Hàng <?php echo($entry[1]) ?>" idedit="<?php echo($entry[0]) ?>" />&nbsp; | &nbsp;<img class="class-delete-link" src="../images/icon-delete.gif" title="Xóa Lãi Suất Trả Góp Ngân Hàng <?php echo($entry[1]) ?>" idedit="<?php echo($entry[0]) ?>" /></td>
        </tr>
        <?php
			}
		} else {
		?>
        <tr><th colspan="8">Không có lãi suất ngân hàng cho vay trả góp</th></tr>
        <?php
		}
		?>
    </table>
</div>
<div><a href="admin.php?content=quanlivay&&as=vay_tra_gop&&adrt=addinstallmentrate"><img src="../images/icon-add.jpg" title="Thêm Lãi Suất Trả Góp Ngân Hàng" />Thêm Lãi Suất Trả Góp Ngân Hàng</a> &nbsp;&nbsp;|&nbsp;&nbsp; <input type="hidden" name="acc" value="del" /><input type="submit" value="Xóa Danh Sách Đã Chọn" style="border-radius: 5px; padding:5px; width:200px; background:#03F; color:#FFF; font-weight:bold;" /></div>
</form>
<script>
loadbank();
function loadbank() {
	$.ajax({
		url: "../src/ajax/ajaxbank.php",
		type: "post",
		data: {act:'getbanks'},
		dataType:"json",
		success: function(response) {
			html = '';
			$.each(response, function(entryIndex, entry){
				html += '<option value="' + entry[0] + '">' + entry[1] + '(' + entry[0] + ')</option>';
			});
			$('.selectbank').append(html);
			$(".selectbank option[value='<?php echo($banksear) ?>']").attr('selected', 'selected');
		}
	});
}

$(document).on('click', '.class-edit-link', function(e) {
	elem = $(this)
	var idcardtype = elem.attr('idedit');
	window.location= 'admin.php?content=quanlivay&&as=vay_tra_gop&&adrt=editinstallmentrate&&id=' + idcardtype;
});

$(document).on('click', '.class-delete-link', function(e) {
	elem = $(this)
	var id = elem.attr('idedit');
	if(confirm("Bạn có muốn xóa?")) {
		$.ajax({
			url: "../src/ajax/ajaxinstallmentrate.php",
			type: "post",
			data: {act:'del', idre: id},
			dataType:"json",
			success: function(data) {
				if(data == true) {
					elem.parent().parent().fadeOut(300, function(){elem.parent().parent().remove();});
				} else {
					alert("Cập nhật dữ liệu không thành công, hoặc mất kết nối internet");
				}
			}
		});
	}
});


$(document).on('click', '.checkall', function(e) {
	if(!$(this).is(':checked')) {
		$('.checkall').attr('title', 'Chọn Tất Cả');
		$('.linecheckall').removeAttr('checked');
	} else {
		$('.checkall').attr('title', 'Bỏ Chọn Tất Cả');
		$('.linecheckall').attr('checked', 'checked');
	}
});
</script>